// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.ast.statement.SQLTableSource_ptr;
// import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause_ptr;
// import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "HiveMultiInsertStatement.h"
#include "HiveInsert.h"
#include "../../../../utils/instanceof.h"
#include "../../../ast/statement/SQLTableSource.h"
#include "../../../ast/statement/SQLWithSubqueryClause.h"
#include "../visitor/HiveASTVisitor.h"
#include "../../../../utils/listTran.h"

HiveMultiInsertStatement::HiveMultiInsertStatement()
    : SQLStatementImpl(DbType_ptr(new DbType(&DbType::hive)))
{
  items = std::make_shared<std::list<HiveInsert_ptr>>();
}

void HiveMultiInsertStatement::setFrom(SQLTableSource_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(HiveMultiInsertStatement));
  }

  this->from = x;
}

SQLTableSource_ptr HiveMultiInsertStatement::getFrom()
{
  return from;
}

HiveInsert_list_ptr HiveMultiInsertStatement::getItems()
{
  return items;
}

void HiveMultiInsertStatement::addItem(HiveInsert_ptr item)
{
  if (item != nullptr)
  {
    item->setParent(SharedObject(HiveMultiInsertStatement));
  }
  this->items->push_back(item);
}

// @Override
void HiveMultiInsertStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof <SQLASTVisitor, HiveASTVisitor>(visitor))
  {
    accept0(std::dynamic_pointer_cast<HiveASTVisitor>(visitor));
  }
  else
  {
    acceptChild(visitor, with);
    acceptChild(visitor, from);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<HiveInsert, SQLObject>(items);
    acceptChild(visitor, tmp1);
  }
}

void HiveMultiInsertStatement::accept0(HiveASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(HiveMultiInsertStatement)))
  {
    acceptChild(visitor, with);
    acceptChild(visitor, from);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<HiveInsert, SQLObject>(items);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(HiveMultiInsertStatement));
}

SQLWithSubqueryClause_ptr HiveMultiInsertStatement::getWith()
{
  return with;
}

void HiveMultiInsertStatement::setWith(SQLWithSubqueryClause_ptr with)
{
  if (with != nullptr)
  {
    with->setParent(SharedObject(HiveMultiInsertStatement));
  }
  this->with = with;
}
